package net.biancheng.bean;

import lombok.Data;
import net.biancheng.common.core.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * @author: lb
 * @date: 2023/7/19 10:40
 * @desc: 系统用户
 **/
@Data
@Entity
@Table(name = "sys_user")
@org.hibernate.annotations.Table(appliesTo = "sys_user", comment = "系统用户表")
public class SysUser extends BaseEntity {

    @Column(name = "dept_id", columnDefinition = "bigint(20) comment '部门ID'")
    private Long deptId;//部门ID

    @Column(name = "user_name", columnDefinition = "varchar(30) comment '登录账号'")
    private String userName;//登录账号

    @Column(name = "nick_name", columnDefinition = "varchar(50) comment '用户昵称'")
    private String nickName;//用户昵称

    @Column(name = "password", columnDefinition = "varchar(100) comment '密码'")
    private String password;//密码

    @Column(name = "phone", columnDefinition = "varchar(11) comment '手机号'")
    private String phone;//手机号

    @Column(name = "sex", columnDefinition = "char(1) comment '用户性别（0男 1女 2未知）'")
    private String sex;//用户性别

    @Column(name = "status", columnDefinition = "char(1) comment '状态 （0启用 1禁用）'")
    private String status;//状态 0-启用 1-禁用

    @Transient
    private Long[] roleIds;//角色组，前端传值回显

    @Transient
    private String deptName;//部门名称，前端显示

    @Transient
    private List<SysRole> roles;//角色列表，前端显示

    //判断用户是否是管理员
    public boolean isAdmin()
    {
        return isAdmin(this.getId());
    }

    public static boolean isAdmin(Long userId)
    {
        return userId != null && 1L == userId;
    }

}
